package cate.game.admin.menu.wallet;

import cate.common.table.d.GDObj;
import cate.common.table.item.fairy.row.FairyBaseRow;
import cate.common.table.item.spice.row.SpiceBaseRow;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.client.msg.MergeMsgSender;
import cate.game.res.MixRes;
import cate.game.res.MixResItem;
import cate.game.role.bag.fairy.Fairy;
import cate.game.role.bag.spice.Spice;
import org.apache.commons.lang3.StringUtils;

public class WalletMenu extends MenuSetup {

    public WalletMenu(GameBody gameBody) {
        super("钱包");

        final String WALLET_TYPE =
                "钱包类型 0：金币，1：元宝，2：银两，3：主角经验，4：英雄经验，5：友情点";

        reg(
                gameBody,
                "改变钱包数量",
                3,
                String.format("【参数1】：%s【参数2】：1：增加（默认），0减少，【参数3】：增加值", WALLET_TYPE),
                (master, params) -> {
                    if (params.size() < 3) {
                        gameBody.notice.message(master, "参数不能少于3个!");
                        return;
                    }
                    byte type = Byte.valueOf(params.get(0));
                    long num = Long.valueOf(params.get(2));

                    MixRes res = new MixRes();
                    res.addItem(new MixResItem(GDObj.Type.NUM, type, num));
                    if (StringUtils.equals("0", params.get(1))) {
                        res.consume(master, null);
                    } else {
                        res.add(master);
                    }
                    // master.wallet.addValue(type, num);
                    // new WalletResp(master).send(master);
                    gameBody.notice.message(master, "已经改变了你的钱包!");
                });


        reg(gameBody, "一键富有", 0,
                "钱包 道具 星格 通用灵器",
                (role, params) -> {
                    MergeMsgSender sender = new MergeMsgSender();
                    // 钱包
                    gameBody.table.item.numRes.list.forEach(row -> {
                        long num = row.getPileMax();//10000000l
                        role.getBag().numRes.addItem(row.id, num, sender);
                    });
                    //道具
                    gameBody.table.item.base.list.forEach(row -> {
                        if (row.gmProducible) {
                            long num = row.getPileMax();//10000000l
                            if (num > 100) {
                                num *= 0.01;
                            }
                            role.getBag().prop.addItem(row.id, num, sender);
                        }
                    });
                    //香料
                    for (SpiceBaseRow baseRow : gameBody.table.spice.base.getList()) {
                        if (baseRow.quality == 5) {
                            int num = 20;
                            while (num-->0){
                                Spice spice = new Spice(role, baseRow.id, 1);
                                spice.level = 10;
                                spice.exp = 0;
                                role.getBag().spice.addItem(spice, sender);
                            }
                        }
                    }
                    //通用灵器
                    for (FairyBaseRow baseRow : gameBody.table.fairy.base.getList()) {
                        if (baseRow.level == 50 && baseRow.type == 1) {
                            int num = 20;
                            while (num-- > 0) {
                                Fairy fairy = new Fairy(role, baseRow.id, 1);
                                role.getBag().getFairy().addItem(fairy, sender);
                            }
                        }
                    }
                    sender.send(role, true);
                    gameBody.notice.message(role, "恭喜发财!");
                });
    }
}
